﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Admin_OrderDownload : OTS.AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TestPurview(HttpContext.Current, OTS.enumSysRight.SalesReport);
        if (!this.Page.IsPostBack)
        {
            string strType = Request.QueryString["type"];
            string strStart = Request.QueryString["start"];
            string strEnd = Request.QueryString["end"];
            if (null == strType || "".Equals(strType) || null == strStart || "".Equals(strStart) || null == strEnd || "".Equals(strEnd))
            {
                Response.Write("参数错误");
                Response.End();
                return;
            }
            if (!OTS.Common.Help.IsDate(strStart) || !OTS.Common.Help.IsDate(strEnd))
            {
                Response.Write("参数错误");
                Response.End();
                return;
            }
            string strConent = "";
            this.lbStart.Text = strStart;
            this.lbEnd.Text = strEnd;
            switch (strType)
            { 
                case "1":
                    this.lbTtile.Text = "已付款（未发货）订单";

                    strConent = GetOrders(strStart, strEnd, "1");
                    break;
                case "2":
                    this.lbTtile.Text = "已发货订单";
                    strConent = GetOrders(strStart, strEnd, "2");
                    break;
                case "3":
                    this.lbTtile.Text = "已售商品单";

                    break;
                default:
                    Response.Write("参数错误");
                    Response.End();
                    return;
                     

            
            }
            this.lbContent.Text = strConent;
        }

    }


    /// <summary>
    /// 获取已付款的订单内容
    /// </summary>
    /// <param name="start"></param>
    /// <param name="end"></param>
    /// <returns></returns>
    private string GetOrders(string start, string end, string status)
    {
        OTS.BLL.SaleOrderBLL bll = new OTS.BLL.SaleOrderBLL();
        end = OTS.Common.Help.GetNextDay(end);
        string strWhere = " status=" + status + " AND addTime>='" + start + "' AND addTime<'" + end + "' ";
        List<OTS.Model.saleOrder> lst =bll.GetList(strWhere,true);
        StringBuilder str = new StringBuilder();
        str.Append("<table id='tblContent' style='width:100%; background:#666666; margin-top:10px;' cellpadding='1' cellspacing='1' border='0'>");
        str.Append("  <tr class='header'>");
        str.Append("    <td style='width:20px;'>NO.</td>");
        str.Append("    <td style='width:100px;'>订单号</td>");
        str.Append("    <td style='width:100px;'>下单时间</td>");
        str.Append("    <td>地址</td>");
        str.Append("    <td style='width:50px;'>收件人</td>");
        str.Append("    <td style=''>电话</td>");
        str.Append("    <td style='width:60px;'>付款方式</td>");
        str.Append("    <td style='width:35px;'>总价</td>");
        str.Append("  </tr>");
        int no,price ;
        for (int i = 0; i < lst.Count; i++)
        {
            no = i + 1;
            str.Append("<tr style='height:20px;'>");
            str.Append("<td >" + no.ToString()  + "</td>");
            str.Append("<td>" + lst[i].orderNO +"</td>");
            str.Append("<td>" + lst[i].addTime +"</td>");
            str.Append("<td>" + lst[i].address +"</td>");
            str.Append("<td>" + lst[i].consignee +"</td>");
            str.Append("<td>" + lst[i].phone + "</td>");
            str.Append("<td>" + lst[i].payMethod + "</td>");
            str.Append("<td style='font-weight:bold;'>" + lst[i].totalMoney.ToString() +"</td>");
            
     
            str.Append("</tr>");

            for (int j = 0; j < lst[i].list.Count; j++)
            {
                OTS.Model.orderDetail model = lst[i].list[j];
                str.Append("<tr style='height:18px;'>");
                str.Append("<td> </td>");
                str.Append("<td style='' align='left' colspan='6'>");
                str.Append("  <div style='width:100%;'><span style='color:#ff0000;border-right:solid 1px #999999;'>");
                str.Append(model.proNO);
                str.Append("  </span>");
                str.Append("  <span>");
                str.Append(model.proName);
                str.Append("(<b>");
                str.Append(model.sizeName);
                str.Append("</b>)");
                str.Append("(<b>");
                str.Append(model.col_color);
                str.Append("</b>)");
                str.Append("  </span>");
                
                str.Append("  <span style='magin-left:5px;border-left:solid 1px #666666;'>&nbsp;价格：<b>");
                str.Append(model.retailPrice);
                str.Append("  </b></span>");
                str.Append("  <span style='magin-left:5px;border-left:solid 1px #666666;'>&nbsp;数量：<b>");
                str.Append(model.pcount);
                str.Append("  </b></span></div>"); 
                str.Append("</td>"); 

                price =Convert.ToInt32( model.retailPrice) * model.pcount;
                str.Append("<td style='color:#333333;'>" + price.ToString() + "</td>");                 
                str.Append("</tr>");

            }
        }
        
        str.Append("</table>");
        return  str.ToString();

    }
}
